<?php 

/**
 * 订单页面控制器
 * @author 妮妮 <962611024@qq.com>
 */
class OrderController extends Controller{
		private $model;
		private $orderlist;
	public function __init(){
		$this->model=K('Gorder');
		$this->orderlist=K('OrderList');
	}
    /**
     * 默认访问方法
     */
    public function index(){
		$gidCheck=Q('post.gidCheck');
		$data=Cart::getGoods();
		$cartData=array();
		foreach ($gidCheck as $id => $value) {
			foreach ($data as $k => $v) {
				if($id==$v['id']){
					$cartData['goods'][]=$v;
				}
			}
		}
		//p($cartData);
		$sum=0;
		foreach ($cartData['goods'] as $k => $v) {
			$sum +=$v['total'];
		}
		$cartData['total']=$sum;
		//购物车已经选好的商品
		$this->assign('cartData',$cartData);
		//地址
		$uid=$_SESSION['uid'];
		$ressData=M('address')->where("uid={$uid}")->find();
		$this->assign('ressData',$ressData);
		//p($ressData);
        $this->display(); 
    }
	/*
	 * 添加到Gorder订单里
	 * */
	public function addOrder(){
		if(IS_POST){
		
			$uid=$_SESSION['uid'];
			$_POST['uid']=$uid;
			if(!$oid=$this->model->orderAdd()) $this->error($this->model->error);
			
			//添加到订单列表中
			
			$combine=Q('post.combine');
			//p($combine);
			//p(Q("post."));die;
			foreach ($combine as $k => $v) {
				$orderlist=array();
				$glid=M("goods_list")->where("combine='$v'")->getField('glid');
				$gid=M("goods_list")->where("combine='$v'")->getField('gid');
				$orderlist['oid']=$oid;
				$orderlist['glid']=$glid;
				$orderlist['quantity']=$_POST['quantity'][$k];
				$orderlist['subtotal']=$_POST['subtotal'][$k];
				$orderlist['gid']=$gid;
				$this->orderlist->add($orderlist);
			}
			//清空购物车中的所有商品 Cart::delAll()
			Cart::delAll();
			//p(Q("post."));
			
			$this->success('订单生成');
		}
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
 }
 
 
 
 
 
 
 
 
 
 
 













































 ?>